package com.ontheroad.mysql.version.service;

import cn.modoumama.service.base.impl.BaseServiceImpl;
import com.ontheroad.api.request.VersionRequest;
import com.ontheroad.api.response.Response;
import com.ontheroad.mysql.version.mapper.VersionMapper;
import com.ontheroad.version.model.VersionModel;
import com.ontheroad.version.service.VersionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by kedong on 2017/8/23 0023.
 */
@Service
@Transactional
public class VersionServiceImpl extends BaseServiceImpl<VersionModel, Integer> implements VersionService {

    Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private VersionMapper mapper;

    @Autowired
    public void setMapper(VersionMapper mapper) {
        setGenericMapper(mapper);
    }

    @Override
    public Response checkNewVersion(VersionRequest request) {
        Integer num = request.getVersionNum();
        Integer type = request.getType();
        VersionModel version = mapper.findNewVersion(num, type);
        Response response = Response.SUCCESS();
        response.addResultData("hasNew", version != null);
        response.addResultData("version", version);
        return response;
    }
}
